CC=gcc

$(shell mkdir -p build)

APP_SRC_DIR=../../openssl_c
TEST_SRC_DIR=.

APP_CFLAGS=-fprofile-arcs -ftest-coverage -I$(APP_SRC_DIR)/include -I../../include
TEST_CFLAGS=-I$(APP_SRC_DIR)/include -I../../include
APP_LDFAGS=-Lbuild -L../../lib -lcrypto -lgcov -Wl,-rpath=build

APP_SRC=rsa.c hmac.c ec.c dh.c dsa.c
APP_OBJ=$(addprefix build/, $(APP_SRC:.c=.o))

TEST_SRC=main-ut.c rsa-ut.c hmac-ut.c ec-ut.c dh-ut.c dsa-ut.c
TEST_OBJ=$(addprefix build/, $(TEST_SRC:.c=.o))

all: clean build/crypto
	cp ../../lib/*.so build
	cp -rf ../../openssl_c ../
	build/crypto
	lcov -b build -d build -c -o build/crypto.info
	mkdir -p build/lcov
	genhtml -o build/lcov build/crypto.info

build/%.o: $(TEST_SRC_DIR)/%.c
	$(CC) -o $@ $^ -c $(TEST_CFLAGS)
build/%.o: $(APP_SRC_DIR)/src/%.c
	$(CC) -o $@ $^ -c $(APP_CFLAGS)
build/crypto: $(APP_OBJ) $(TEST_OBJ)
	$(CC) -o $@ $^ $(APP_LDFAGS)


clean:
	rm -rf build/*  build/crypto

.PHONY: all clean